from PyQt4.QtGui import *

class Wizard(QWizard):

   def __init__(self, text):
      wx.wizard.Wizard.__init__(self, wx.GetApp().GetFrame(), wx.ID_ANY, text)
      self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGING, self.__OnPageChange)
      self.pages = {}

   def run(self):
      if self.RunWizard(self.pages[0]):
         self.complete()
         return True
      else:
         return False

   def complete(self):
      '''This should be overloaded by inherited classes to define any actions
      at the end of the wizard, e.g. updating the gui.'''
      pass

   def __OnPageChange(self, event):
      prev = event.GetPage()
      next = prev.GetNext() if event.GetDirection() else prev.GetPrev()
      if not self.OnPageChange(prev, next):
         event.Veto()

   def OnPageChange(self, prev, next):
      """ This should be overloaded to handle the page change event.  The
      return value specifies whether to accept the event.
      """
      return True

   def result(self):
      """ Return the results of the wizard in a tuple so that it can be
      passed as an argument to the relevant command object.
      """
      pass
